using FSM.Dal; 
using FSM.IDal; 
using FSM.IBll; 
using FSM.Model; 
using SqlSugar; 
using System; 
using System.Collections.Generic; 
using System.Text; 
using Util.Excel; 
 
namespace FSM.Bll 
{ 
    public class TbFileLogBll: ITbFileLogBll 
    { 
        #region 模块 
        private readonly ITbFileLogDal _dal; 
        private readonly IExcelAssistant _excel; 
        public TbFileLogBll(ITbFileLogDal dal, IExcelAssistant excel) 
        { 
            _dal = dal; 
            _excel = excel; 
        } 
        #endregion 
 
        #region 查询 
 
        /// <summary> 
        /// 根据键值查询单个信息 
        /// </summary> 
        /// <param name="id">键值</param> 
        /// <returns></returns> 
        public tb_file_log Get(int id) 
        { 
            return _dal.GetById(id); 
        } 
 
        /// <summary> 
        /// 分页查询批量信息 
        /// </summary> 
        /// <param name="file_id">文件及文件夹ID</param> 
        /// <param name="page">页码</param> 
        /// <param name="page_size">每页显示的条数</param> 
        /// <returns></returns> 
        public Tuple<List<tb_file_log>, int> ListPagin(int? file_id, int page, int page_size) 
        { 
            ISugarQueryable<tb_file_log> queryable = _dal.CreateQueryable(); 
            queryable = queryable.WhereIF(file_id!=null,p => p.file_id == file_id); 
             
            PageModel pm = new PageModel 
            { 
                PageIndex = page, 
                PageSize = page_size 
            }; 
            Tuple<List<tb_file_log>, int> result = _dal.GetPageListAndTotal(queryable, pm); 
            return result; 
        } 
 
        /// <summary> 
        /// 分页查询批量信息 
        /// </summary> 
        /// <param name="file_id">文件及文件夹ID</param> 
        /// <returns></returns> 
        public List<tb_file_log> List(int? file_id) 
        { 
            Expressionable<tb_file_log> queryable = Expressionable.Create<tb_file_log>(); 
            queryable = queryable.AndIF(file_id!=null,p => p.file_id == file_id); 
             
            List<tb_file_log> result = _dal.GetList(queryable.ToExpression()); 
            return result; 
        } 
 
        #endregion 
 
        #region 提交 
 
        /// <summary> 
        /// 添加 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        public bool Insert(tb_file_log model) 
        { 
            int id = _dal.InsertReturnIdentity(model);
            model.id = id;
            return true;
        } 
 
        /// <summary> 
        /// 更新 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        public bool Update(tb_file_log model) 
        { 
            return _dal.UpdateExcludeColumns(model, "creater", "create_date") == 1; 
        } 
 
        /// <summary> 
        ///  删除 
        /// </summary> 
        /// <param name="id_arr">键值</param> 
        /// <returns></returns> 
        public bool Delete(params int?[] id_arr) 
        { 
            return _dal.Delete(id_arr); 
        } 
 
        /// <summary> 
        /// 获得要导出的数据的Excel流 
        /// </summary> 
        /// <param name="file_id">文件及文件夹ID</param> 
        /// <returns></returns> 
        public byte[] Export(int? file_id) 
        { 
            List<tb_file_log> result = List(file_id); 
            return _excel.Collection2ExcelBytes(result, "Sheet1"); 
        } 
        #endregion 
    } 
} 
